﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace APMS.WebSite
{
    public class GlobalApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Special route which allow anonymous access
            // Register
            routes.MapRoute(
                "RegisterNewUser",      // Route name
                "Register",       // URL with parameters
                new { controller = "User", action = "Create" } // Parameter constraints
            );

            // Route for User actions - not need projectId
            routes.MapRoute(
                "User",      // Route name
                "User/{action}/{id}",       // URL with parameters
                new { controller = "User", action = "Login", id="" } // Parameter constraints
            );

            // Route for Global Projects action - not need projectId
            routes.MapRoute(
                "Projects",      // Route name
                "Project/{action}/{id}",       // URL with parameters
                new { controller = "Project", action = "List" , id = "" } // Parameter constraints
            );

            // Route for Local Project action - need projectId
            routes.MapRoute(
                "InProject",      // Route name
                "InProject/{projectId}/{controller}/{action}/{id}",       // URL with parameters
                new { projectId = "", controller = "", action = "List", id = "" } // Parameter constraints
            );

            //// Route for Local Project action - need projectId
            //routes.MapRoute(
            //    "Project",      // Route name
            //    "PreviewProject/{projectId}/{controller}/{action}/{id}",       // URL with parameters
            //    new { projectId = "", controller = "", action = "", id = "" } // Parameter constraints
            //);
            //// ---------------------------- OAT ADDed
            //routes.MapRoute(
            //        "chat",      // Route name
            //        "PreviewProject/{projectId}/chat/{chatId}/{controller}/{action}/{id}",       // URL with parameters
            //        new { projectId = "", chatId = "", controller = "", action = "", id = "" } // Parameter constraints
            //    );
            //routes.MapRoute(
            //        "todo",      // Route name
            //        "PreviewProject/{projectId}/todo/{todoId}/{controller}/{action}/{id}",       // URL with parameters
            //        new { projectId = "", todoId = "", controller = "", action = "", id = "" } // Parameter constraints
            //    );
            //routes.MapRoute(
            //        "message",      // Route name
            //        "PreviewProject/{projectId}/message/{messageId}/{controller}/{action}/{id}",       // URL with parameters
            //        new { projectId = "", messageId = "", controller = "", action = "", id = "" } // Parameter constraints
            //    );
            //routes.MapRoute(
            //        "writeboard",      // Route name
            //        "PreviewProject/{projectId}/writeboard/{writeboardId}/{controller}/{action}/{id}",       // URL with parameters
            //        new { projectId = "", writeboardId = "", controller = "", action = "", id = "" } // Parameter constraints
            //    );
            //---------------------------------------------------------
            //// Route under local project
            //routes.MapRoute(
            //    "Default",                                              // Route name
            //    "{project}/{controller}/{action}/{id}",                 // URL with parameters
            //    new { project = "None", controller = "Home", action = "Index", id = "" }  // Parameter defaults
            //);

            // TODO: Use {controller}.mvc/{action}/{id} in production, and the request url must append .mvc after controller
            // This is work around with IIS5.1 (XP) and IIS6 (Windows 2003) - Note that you must map .mvc extension to the IIS
            // Read more details at http://forums.asp.net/p/1290196/2499522.aspx

            // Default value
            // {controller}/{action}/{id}
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}